package com.you.place.dal.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.you.common.ibatis.AbstractDAO;
import com.you.place.dal.dao.dataobject.NotePhotoDO;

@SuppressWarnings({ "unchecked", "rawtypes" })
public class NotePhotoDAO extends AbstractDAO {

    public Map<String, String> queryMapByNoteItemId(Long noteItemId) {
        List<NotePhotoDO> notePhotoList = queryByNoteItemId(noteItemId);
        Map<String, String> result = new HashMap<String, String>();
        for (NotePhotoDO notePhoto : notePhotoList) {
            result.put(notePhoto.getName(), notePhoto.getImgUrl());
        }
        return result;
    }

    public List<NotePhotoDO> queryByNoteItemId(Long noteItemId) {

        return super.getSqlMapClientTemplate().queryForList("MS-SELECT-NOTE-PHOTO-BY-NOTE-ITEM-ID", noteItemId);
    }
    
    public List<NotePhotoDO> queryByMemberId(Long memberId) {

        return super.getSqlMapClientTemplate().queryForList("MS-SELECT-NOTE-PHOTO-BY-MEMBRE-ID", memberId);
    }
    
    public Integer delete(Long id){
        
        return super.getSqlMapClientTemplate().delete("MS-DELETE-NOTE-PHOTO",id);
    }
    
    public Long create(NotePhotoDO notePhotoDO){
        
        return (Long) super.getSqlMapClientTemplate().insert("MS-CREATE-NOTE-PHOTO",notePhotoDO);
    }
    
    public Integer updateNoteItemId(Long memberId,Long noteItemId){
        Map param = new HashMap();
        param.put("noteItemId", noteItemId);
        param.put("memberId", memberId);
        return super.getSqlMapClientTemplate().update("MS-UPDATE-NOTE-PHOTO-ITEM-ID", param);
    }
}
